package com.sm.controller;

import com.sm.model.Banner;
import com.sm.model.HomeIcon;
import com.sm.service.BannerService;
import com.sm.service.HomeIconService;
import com.sm.service.VideoCourseService;
import com.sm.util.Msg;
import com.sm.util.PageResult;
import com.sm.vo.HomeMemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/school")
public class TopSchoolController {

    @Autowired
    private BannerService bannerService;
    @Autowired
    private HomeIconService homeIconService;
    @Autowired
    private VideoCourseService videoCourseService;

    /**
     * 状元学堂轮播图和金刚区
     */
    @RequestMapping("/schoolBanner")
    @ResponseBody
    public Msg banner(){
        List<Banner> banners = bannerService.selectBannerPic(1);
        List<HomeIcon> schoolIncons = homeIconService.selectSchoolIncons();
        return Msg.success().add("banners",banners).add("icons",schoolIncons);
    }

    /**
     *  金刚区下面的创意美术，助梦舞蹈，传媒口才，国学启蒙，潜能开发五个模块
     */
    @RequestMapping("/schoolMember")
    @ResponseBody
    public Msg schoolMember(){
        ArrayList<HomeMemberVo> schoolMembers = new ArrayList<>();
        //拼接创意美术
        HomeMemberVo cyms = new HomeMemberVo("cyms");
        cyms.setAsName("创意美术");
        cyms.setFirstId(5);
        PageResult cymsVideos = videoCourseService.selectFirstAllVideo(5, 1, 3);
        cyms.setList(cymsVideos.getRows());
        schoolMembers.add(cyms);
        //拼接助梦舞蹈
        HomeMemberVo zmwd = new HomeMemberVo("zmwd");
        zmwd.setAsName("助梦舞蹈");
        zmwd.setFirstId(6);
        PageResult zmwdVideos = videoCourseService.selectFirstAllVideo(6, 1, 3);
        zmwd.setList(zmwdVideos.getRows());
        schoolMembers.add(zmwd);
        //拼接传媒口才
        HomeMemberVo cmkc = new HomeMemberVo("cmkc");
        cmkc.setAsName("传媒口才");
        cmkc.setFirstId(7);
        PageResult cmkcVideos = videoCourseService.selectFirstAllVideo(7, 1, 3);
        cmkc.setList(cmkcVideos.getRows());
        schoolMembers.add(cmkc);
        //拼接王者悦读
        HomeMemberVo wzyd = new HomeMemberVo("wzyd");
        wzyd.setAsName("王者悦读");
        wzyd.setFirstId(8);
        PageResult wzydVideos = videoCourseService.selectFirstAllVideo(8, 1, 3);
        wzyd.setList(wzydVideos.getRows());
        schoolMembers.add(wzyd);
        //拼接国学阅读
        HomeMemberVo gxyd = new HomeMemberVo("gxyd");
        gxyd.setAsName("国学阅读");
        gxyd.setFirstId(9);
        PageResult gxydVideos = videoCourseService.selectFirstAllVideo(9, 1, 3);
        gxyd.setList(gxydVideos.getRows());
        schoolMembers.add(gxyd);
        //拼接国学启蒙
        HomeMemberVo gxqm = new HomeMemberVo("gxqm");
        gxqm.setAsName("国学启蒙");
        gxqm.setFirstId(10);
        PageResult gxqmVideos = videoCourseService.selectFirstAllVideo(10, 1, 3);
        gxqm.setList(gxqmVideos.getRows());
        schoolMembers.add(gxqm);
        //拼接国学拼音
        HomeMemberVo gxpy = new HomeMemberVo("gxpy");
        gxpy.setAsName("国学拼音");
        gxpy.setFirstId(11);
        PageResult gxpyVideos = videoCourseService.selectFirstAllVideo(11, 1, 3);
        gxpy.setList(gxpyVideos.getRows());
        schoolMembers.add(gxpy);
        //拼接潜能开发
        HomeMemberVo qnkf = new HomeMemberVo("qnkf");
        qnkf.setAsName("潜能开发");
        qnkf.setFirstId(12);
        PageResult qnkfVideos = videoCourseService.selectFirstAllVideo(12, 1, 3);
        qnkf.setList(qnkfVideos.getRows());
        schoolMembers.add(qnkf);
        return Msg.success(schoolMembers);
    }


    /**
     * 状元学堂金刚区及以下三部分列表页(状元学堂点击图标拉取课程列表)
     */
    @RequestMapping("/getListByIcon")
    @ResponseBody
    public Msg getListByIcon(Integer firstDirectoryId, Integer currentPage, Integer pageSize, @RequestParam(value = "secondDirectoryId",required = false)Integer secondDirectoryId){
        if (firstDirectoryId == null){
            return Msg.fail().add("msg","参数为空");
        }
        PageResult pageResult = videoCourseService.selectVideoByFirsetAndSecond(firstDirectoryId, secondDirectoryId, currentPage, pageSize);
        if (ObjectUtils.isEmpty(pageResult)){
            return Msg.success().add("msg","暂无数据");
        }
        return Msg.success(pageResult);
    }







}
